package org.jeecg.modules.imm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.imm.entity.ImmInvestorMsg;
import org.jeecg.modules.imm.mapper.ImmInvestorMsgMapper;
import org.jeecg.modules.imm.service.ImmInvestorMsgService;
import org.jeecg.modules.scm.api.ScmCommonCloudApi;
import org.jeecg.modules.scm.dto.EditInvItemRsDto;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description: imm_investor_item
 * @Author: jeecg-boot
 * @Date: 2021-12-09
 * @Version: V1.0
 */
@Service
public class ImmInvestorMsgServiceImpl extends ServiceImpl<ImmInvestorMsgMapper, ImmInvestorMsg> implements ImmInvestorMsgService {

    @Resource
    private ScmCommonCloudApi scmCommonCloudApi;

    @Override
    public Result<?> saveAndUpdateInvItem(ImmInvestorMsg immInvestorMsg) {
        Result<Object> result = null;
        boolean save = this.save(immInvestorMsg);
        if (!save) {
            result = new Result<>();
            result.setCode(5001);
            result.setMessage("消息保存失败");
            result.setResult(immInvestorMsg);
        }
        // TODO 信息不全
        EditInvItemRsDto dto = new EditInvItemRsDto();
        BeanUtils.copyProperties(immInvestorMsg, dto);
        Result<Boolean> bResult = scmCommonCloudApi.updateByInvMsg(dto);
        if (null == bResult || !bResult.isSuccess()) {
            result = new Result<>();
            result.setCode(5001);
            result.setMessage("更新失败");
            result.setResult(immInvestorMsg);
        }
        result = Result.OK(immInvestorMsg);
        return result;
    }
}
